<template>
    <div class="default-main ba-table-box">
        <el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />

        <!-- 表格顶部菜单 -->
        <!-- 自定义按钮请使用插槽，甚至公共搜索也可以使用具名插槽渲染，参见文档 -->
        <TableHeader
            :buttons="['refresh', 'add', 'edit', 'delete', 'comSearch', 'quickSearch', 'columnDisplay']"
            :quick-search-placeholder="t('Quick search placeholder', { fields: t('shopapply.quick Search Fields') })"
        ></TableHeader>

        <!-- 表格 -->
        <!-- 表格列有多种自定义渲染方式，比如自定义组件、具名插槽等，参见文档 -->
        <!-- 要使用 el-table 组件原有的属性，直接加在 Table 标签上即可 -->
        <Table ref="tableRef"></Table>

        <!-- 表单 -->
        <PopupForm />




        <!--审核-->
        <el-dialog
            v-model="check_show"
            width="500"

        >
            <template #header>
                <div class="title" style="border-bottom:1px solid var(--ba-bg-color);padding-bottom: 16px;" v-drag="['.ba-operate-dialog', '.el-dialog__header']" v-zoom="'.ba-operate-dialog'">
                    审核入驻申请
                </div>
            </template>
<!--            提示：<br>-->
<!--            &nbsp;&nbsp;&nbsp;&nbsp;1、默认将联系方式字段;<br>-->
<!--            &nbsp;&nbsp;&nbsp;&nbsp;2、机具号为唯一标识，如果新导入的绑定数据已在订单中，将导入失败！<br>-->
<!--            <br><br>-->
            <div  class="el-form-item asterisk-left" style="margin-top: -15px">
                <label id="el-id-9147-66" for="el-id-9147-69" class="el-form-item__label">商家名称</label>
                <div class="el-form-item__content">
                    {{check_data.name}}
                </div>
            </div>
            <div  class="el-form-item asterisk-left">
                <label id="el-id-9147-66" for="el-id-9147-69" class="el-form-item__label">联系方式</label>
                <div class="el-form-item__content">
                    {{check_data.phone}}
                </div>
            </div>
            <FormItem :label="t('shopapply.status')" type="radio"  v-model="check_data.status_"  :data="{ content: {  '1': t('shopapply.status 1'), '2': t('shopapply.status 2') } }" :placeholder="t('Please select field', { field: t('shopapply.status') })" />

            <FormItem label="账号" type="string" v-if="check_data.status_ == 1" v-model="check_data.account" prop="account" placeholder="请输入后台登录账号" />
            <FormItem label="密码" type="password" v-if="check_data.status_ == 1"  v-model="check_data.password" placeholder="请输入后台登录密码" />

            <FormItem label="驳回理由" type="textarea" v-if="check_data.status_ == 2"  v-model="check_data.reason_" placeholder="请输入驳回理由" />

            <template #footer>
                <div class="dialog-footer">
                    <el-button @click="check_show = false">取消</el-button>
                    <el-button type="primary" @click="sub_check">
                        确认
                    </el-button>
                </div>
            </template>
        </el-dialog>
    </div>
</template>

<script setup lang="ts">
import { onMounted, provide, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import PopupForm from './popupForm.vue'
import { baTableApi } from '/@/api/common'
import { defaultOptButtons } from '/@/components/table'
import TableHeader from '/@/components/table/header/index.vue'
import Table from '/@/components/table/index.vue'
import baTableClass from '/@/utils/baTable'
import {auth} from "/@/utils/common";
import FormItem from '/@/components/formItem/index.vue'
import createAxios from "/@/utils/axios";
import {ElMessage} from "element-plus";

defineOptions({
    name: 'shopapply',
})

const { t } = useI18n()
const tableRef = ref()
const optButtons: OptButton[] = defaultOptButtons(['edit', 'delete'])

const auth_check = auth({ name: '/admin/shopapply', subNodeName: '/admin/shopapply/check' })

optButtons.push(
    {
        render: 'tipButton',
        name: 'check',
        title: '审核',
        text: '',
        type: 'primary',
        icon: 'fa fa-check-square-o',
        class: 'table-row-info',
        click(row, field) {
            check_data.value = row;
            check_show.value = true;
            // id.value = row.id;
        },
        display: (row, field) => {
            if (auth_check && row.status == 0)
            {
                return true
            }else {
                return false;
            }
        },
    },
)
/**
 * baTable 内包含了表格的所有数据且数据具备响应性，然后通过 provide 注入给了后代组件
 */
const baTable = new baTableClass(
    new baTableApi('/admin/Shopapply/'),
    {
        pk: 'id',
        column: [
            { type: 'selection', align: 'center', operator: false },
            { label: t('shopapply.id'), prop: 'id', align: 'center', width: 70, operator: 'RANGE', sortable: 'custom' },
            // { label: t('shopapply.shop_id'), prop: 'shop_id', align: 'center', operator: 'RANGE', sortable: false },
            { label: t('shopapply.user__nickname'), prop: 'user.nickname', align: 'center', operatorPlaceholder: t('Fuzzy query'),  operator: 'LIKE' },
            { label: t('shopapply.city'), prop: 'city_text', align: 'center', operator: false },
            { label: t('shopapply.name'), prop: 'name', align: 'center', operatorPlaceholder: t('Fuzzy query'), operator: 'LIKE', sortable: false },
            { label: t('shopapply.wx_number'), prop: 'wx_number', align: 'center', operatorPlaceholder: t('Fuzzy query'), operator: 'LIKE', sortable: false },
            { label: t('shopapply.phone'), prop: 'phone', align: 'center', operatorPlaceholder: t('Fuzzy query'), operator: 'LIKE', sortable: false },
            { label: t('shopapply.image'), prop: 'image', align: 'center', render: 'image', operator: false },
            { label: t('shopapply.images'), prop: 'images', align: 'center', render: 'images', operator: false },
            { label: t('shopapply.business_image'), prop: 'business_image', align: 'center', render: 'image', operator: false },
            { label: t('shopapply.status'), prop: 'status', align: 'center', render: 'tag', operator: 'eq', sortable: false, replaceValue: { '0': t('shopapply.status 0'), '1': t('shopapply.status 1'), '2': t('shopapply.status 2') } },
            // { label: t('shopapply.admin__nickname'), prop: 'admin.nickname', align: 'center', operatorPlaceholder: t('Fuzzy query'), render: 'tags', operator: 'LIKE' },

            { label: t('shopapply.reason'), prop: 'reason', align: 'center', operator: false },
            { label: t('shopapply.check_time'), prop: 'check_time', align: 'center', render: 'datetime', operator: 'RANGE', sortable: 'custom', width: 160, timeFormat: 'yyyy-mm-dd hh:MM:ss' },
            { label: t('shopapply.create_time'), prop: 'create_time', align: 'center', render: 'datetime', operator: 'RANGE', sortable: 'custom', width: 160, timeFormat: 'yyyy-mm-dd hh:MM:ss' },
            // { label: t('shopapply.update_time'), prop: 'update_time', align: 'center', render: 'datetime', operator: 'RANGE', sortable: 'custom', width: 160, timeFormat: 'yyyy-mm-dd hh:MM:ss' },
            { label: t('Operate'), align: 'center', width: 100, render: 'buttons', buttons: optButtons, operator: false },
        ],
        dblClickNotEditColumn: false,
    },
    {
        defaultItems: { shop_id: 0, status: '0', check_time: null },
    }
)

provide('baTable', baTable)

onMounted(() => {
    baTable.table.ref = tableRef.value
    baTable.mount()
    baTable.getIndex()?.then(() => {
        baTable.initSort()
        baTable.dragSort()
    })
})

const id = ref(0);

/**
 * 审核
 */
const check_data = ref({});
const check_show = ref(false);
const sub_check = () => {
    createAxios({
        url: '/admin/shopapply/check',
        method: 'post',
        data: check_data.value
    },{
        loading:true
    },{
        text: '审核提交中...'
    })
        .then((res) => {
            if (res.code == 1){
                ElMessage({
                    message: res.msg,
                    type: 'success',
                })
                baTable.onTableHeaderAction('refresh', {})
                check_show.value = false;
                check_data.value = '';
            }else {
                ElMessage({
                    message: res.msg,
                    type: 'error',
                })
            }

        })
        .catch((resx) => {
        })
}
</script>

<style scoped lang="scss"></style>
